package Utils;

use LWP::UserAgent;

use Exporter qw( import );
our @EXPORT = qw( fetch_url_contents ) ;


sub fetch_url_contents {
	# TODO: Decide if we should log HTTP status codes or return to caller. As of now
	# an empty string is returned if there was an error.

	my $html_contents = '';

	my $ua = LWP::UserAgent->new('jeyamohans-archive-bot');
	$ua->timeout(20);
	$ua->env_proxy;

	my $response = $ua->get($_[0]);
	if ($response->is_success) {
		$html_contents = $response->decoded_content;
	}
	else {
		$html_contents = '';
	}

	$html_contents;
}